package javase.io;



import java.io.*;

/**
 * 文件字符流 读取文件
 * @author LiShaowen
 * @date 2020/9/8 23:46
 */
public class FileReaderTest {
    public static void main(String[] args) {
        // 1.创建源
        File file = new File("src/main/java/javase/io/lsw.txt");
        // 2.选择流
        FileReader reader = null;
        try {
            reader = new FileReader(file);
            // 3.操作（读取）
            char[] cbuf = new char[2];
            int length;
            while ((length = reader.read(cbuf)) != -1) {
                System.out.println(new String(cbuf,0,length));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (null!=reader) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
